package org.ala.tiktools.generator.mybatis.creator.shard;

import org.ala.tiktools.generator.mybatis.config.info.Part;
import org.ala.tiktools.generator.mybatis.creator.entity.EntityInfo;
import org.ala.tiktools.generator.mybatis.dbinfo.TableInfo;
import org.ala.tiktools.generator.mybatis.tools.Tools;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ala
 * @date 2025-02-25 14:37
 */
public class ShardRouterInfo {

    protected TableInfo t;
    protected EntityInfo e;

    protected String pkg;
    protected String className;

    protected String router, routerClassName;

    protected List<String> imports = new ArrayList<>();
    protected String generics, genericsClassName;

    protected String shardInfo, shardInfoClassName;

    public static ShardRouterInfo build(Part part, TableInfo t, EntityInfo e, String generics, boolean isList) {
        ShardRouterInfo sri = new ShardRouterInfo();
        sri.t = t; sri.e = e;

        sri.pkg = part.getOut().getShard().getPkg() + ".router";

        sri.router = part.getOut().getShard().getRouter();
        sri.routerClassName = Tools.parseClassName(sri.router);

        sri.generics = generics;
        sri.genericsClassName = Tools.parseClassName(generics);

        sri.className = sri.genericsClassName + "Router";

        sri.shardInfo = part.getOut().getShard().getShardInfo();
        sri.shardInfoClassName = Tools.parseClassName(sri.shardInfo);

        sri.imports.add("java.util.Collections");
        sri.imports.add("java.util.Map");
        sri.imports.add(sri.router);
        sri.imports.add(generics);
        sri.imports.add(sri.shardInfo);
        if (isList) {
            sri.imports.add("java.util.List");
            sri.className = sri.genericsClassName + "ListRouter";
            sri.genericsClassName = String.format("List<%s>", sri.genericsClassName);
        }

        return sri;
    }

    public String getPkg() {
        return pkg;
    }

    public void setPkg(String pkg) {
        this.pkg = pkg;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public List<String> getImports() {
        return imports;
    }

    public void setImports(List<String> imports) {
        this.imports = imports;
    }

    public String getGenerics() {
        return generics;
    }

    public void setGenerics(String generics) {
        this.generics = generics;
    }

    public String getGenericsClassName() {
        return genericsClassName;
    }

    public void setGenericsClassName(String genericsClassName) {
        this.genericsClassName = genericsClassName;
    }

    public TableInfo getT() {
        return t;
    }

    public void setT(TableInfo t) {
        this.t = t;
    }

    public EntityInfo getE() {
        return e;
    }

    public void setE(EntityInfo e) {
        this.e = e;
    }

    public String getRouter() {
        return router;
    }

    public void setRouter(String router) {
        this.router = router;
    }

    public String getRouterClassName() {
        return routerClassName;
    }

    public void setRouterClassName(String routerClassName) {
        this.routerClassName = routerClassName;
    }

    public String getShardInfo() {
        return shardInfo;
    }

    public void setShardInfo(String shardInfo) {
        this.shardInfo = shardInfo;
    }

    public String getShardInfoClassName() {
        return shardInfoClassName;
    }

    public void setShardInfoClassName(String shardInfoClassName) {
        this.shardInfoClassName = shardInfoClassName;
    }
}
